<template>
    <div class="right-container">
        <h3>Right 组件 --- {{ count }}</h3>
        <button @click="add">+1</button>
        <hr />
        <p>{{ msgFromLeft }}</p>
    </div>
</template>

<script>
    import bus from './EventBus.js'

    export default {
        data() {
            return {
                count: 0,
                msgFromLeft: 'Left未传值'
            }
        },
        methods: {
            add() {
                this.count += 1
                // 子组件向父组件共享数据
                // 通过 $emit 自定义事件  PS：click事件原理 this.$emit('click', {clientX: 0...}(e对象))
                this.$emit('numchange', this.count)
            }
        },
        created() {
            bus.$on('share', (val) => {
                this.msgFromLeft = val
            })
        }
    }
</script>

<style lang="less" scoped>
.right-container {
    padding: 0 20px 20px;
    background-color: lightskyblue;
    min-height: 250px;
    flex: 1;
}
</style>